/*
 * Singularity Engine
 * Copyright (C) 2010 Vyacheslav Vorobyov, All rights reserved.
 * See LICENSE for full license information.
 */

/**
 * 
 */
package org.singularity.mapred;

import org.singularity.io.DME;
import org.singularity.io.Pipe;

/**
 * This interface is used to specify a function responsible 
 * for folding a joined vector streams (key-value pairs) 
 * obtained from sevral sources to a single scalar stream 
 * (values).
 * 
 * @author vjache
 *
 * @param <KT> - a key type of a key-value pairs to be joined and folded.
 * @param <RT> - a type of values that are results of a fold. 
 */
public interface RedFun<KT,RT> {
	/**
	 * This function designed to fold a key-value pairs 
	 * obtained from several sources for a given key.
	 * 
	 * @param aDmeCode - a code of an event.
	 * @param aOut - a pipe for returning a folded results.
	 * @param aKey - a key part of a key-value pairs to be joined and folded.
	 * @param aSources - an array of collections one per source. Each 
	 * collection contains a value part of key-value pairs.
	 * @throws Exception
	 */
	void red(
			DME.Code aDmeCode, 
			Pipe<DME<RT>> aOut, 
			KT aKey, 
			Iterable<?>... aSources) throws Exception;
}
